
from collections import defaultdict
from functools import lru_cache
from typing import Dict
from warnings import warn

from ygframe.util.import_util import get_all

from service.implementation import Implementation

__author__ = 'jing'


@lru_cache()
def get_services() -> Dict[str, Dict[str, type]]:
    mapper = defaultdict(dict)
    for impl in get_all('service.implementation', Implementation):
        if issubclass(impl, Implementation):
            if not impl.__container__ or not impl.__resource__:
                warn('Implementation must has __container__ and __resource__')
                continue
            mapper[impl.__container__][impl.__resource__] = impl
    return mapper


if __name__ == '__main__':
    print(get_services())
